import 'package:flutter/material.dart';

// 自定义的 InheritedWidget，用于共享计数器数据
//InheritedWidget 是用于小部件共享状态
class CounterProvider extends InheritedWidget {
  final int count;
  final Widget child;

  const CounterProvider({
    required this.count,
    required this.child,
  }) : super(child: child);

  // 静态方法，用于在子树中查找最近的 CounterProvider 实例
  static CounterProvider? of(BuildContext context) {
    return context.dependOnInheritedWidgetOfExactType<CounterProvider>();
  }

  // 当 count 发生变化时，决定是否通知子小部件
  @override
  bool updateShouldNotify(CounterProvider oldWidget) {
    // TODO: implement updateShouldNotify
    return oldWidget.count != count;
  }
}
